using System.Collections.Generic;

namespace Pdf2epub.Model
{
    public class Chapter : BaseObject
    {
        public Chapter()
        {
        }

        public Chapter(Chapter parentChapter, string chapterHeader)
        {
            ParentChapter = parentChapter;
            Headline = chapterHeader;
            SubChapters = new List<Chapter>();
        }

        public string Headline { get; set; }

        public Chapter ParentChapter { get; set; }

        public List<Chapter> SubChapters { get; set; }

        public bool IsPartOfTopLevelChapter(Chapter topLevelChapter)
        {
            Chapter workChapter = this;
            while (workChapter.ParentChapter != null)
            {
                workChapter = workChapter.ParentChapter;
            }
            return workChapter == topLevelChapter;
        }

        public override string ToString()
        {
            return Headline;
        }
    }
}